﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RN.ERP.Web.Token
{
    public partial class GetToken : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["BackURL"] != null && Request.QueryString["BackURL"] != "")
                {
                    string backURL = Server.UrlDecode(Request.QueryString["BackURL"]);
                    string token = "";
                    token = Session["token2"] == null ? string.Empty : Session["token2"].ToString();
                    if (string.IsNullOrEmpty(token))
                    {
                        var cookie = Request.Cookies["LoginToken"];
                        if (cookie != null)
                        {
                            token = cookie.Value;
                            Session["token2"] = token;
                        }
                    }
                    if (!string.IsNullOrEmpty(token))
                        backURL = backURL.Replace("$Token$", token);
                    Response.Redirect(backURL);
                }
            }

           
        }
    }
}